{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This notebook verifies `doc/python/*.py`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# BACCAB.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sympy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from __future__ import absolute_import, division\n",
    "from __future__ import print_function\n",
    "from galgebra.printer import Format, xpdf\n",
    "from galgebra.ga import Ga"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "Format()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "g4d = Ga('a b c d')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "(a, b, c, d) = g4d.mv()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\left (\\mathbf{a}\\cdot \\mathbf{a}\\right )  & \\left (\\mathbf{a}\\cdot \\mathbf{b}\\right )  & \\left (\\mathbf{a}\\cdot \\mathbf{c}\\right )  & \\left (\\mathbf{a}\\cdot \\mathbf{d}\\right ) \\\\\\left (\\mathbf{a}\\cdot \\mathbf{b}\\right )  & \\left (\\mathbf{b}\\cdot \\mathbf{b}\\right )  & \\left (\\mathbf{b}\\cdot \\mathbf{c}\\right )  & \\left (\\mathbf{b}\\cdot \\mathbf{d}\\right ) \\\\\\left (\\mathbf{a}\\cdot \\mathbf{c}\\right )  & \\left (\\mathbf{b}\\cdot \\mathbf{c}\\right )  & \\left (\\mathbf{c}\\cdot \\mathbf{c}\\right )  & \\left (\\mathbf{c}\\cdot \\mathbf{d}\\right ) \\\\\\left (\\mathbf{a}\\cdot \\mathbf{d}\\right )  & \\left (\\mathbf{b}\\cdot \\mathbf{d}\\right )  & \\left (\\mathbf{c}\\cdot \\mathbf{d}\\right )  & \\left (\\mathbf{d}\\cdot \\mathbf{d}\\right ) \\end{matrix}\\right]$"
      ],
      "text/plain": [
       "Matrix([\n",
       "[(a.a), (a.b), (a.c), (a.d)],\n",
       "[(a.b), (b.b), (b.c), (b.d)],\n",
       "[(a.c), (b.c), (c.c), (c.d)],\n",
       "[(a.d), (b.d), (c.d), (d.d)]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g4d.g"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} - \\left (\\boldsymbol{a}\\cdot \\boldsymbol{c}\\right )  \\boldsymbol{b} + \\left (\\boldsymbol{a}\\cdot \\boldsymbol{b}\\right )  \\boldsymbol{c} \\end{equation*}"
      ],
      "text/plain": [
       "-(a.c)*b + (a.b)*c"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a | (b * c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} - \\left (\\boldsymbol{a}\\cdot \\boldsymbol{c}\\right )  \\boldsymbol{b} + \\left (\\boldsymbol{a}\\cdot \\boldsymbol{b}\\right )  \\boldsymbol{c} \\end{equation*}"
      ],
      "text/plain": [
       "-(a.c)*b + (a.b)*c"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a | (b ^ c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} \\left (\\boldsymbol{a}\\cdot \\boldsymbol{d}\\right )  \\boldsymbol{b}\\wedge \\boldsymbol{c} - \\left (\\boldsymbol{a}\\cdot \\boldsymbol{c}\\right )  \\boldsymbol{b}\\wedge \\boldsymbol{d} + \\left (\\boldsymbol{a}\\cdot \\boldsymbol{b}\\right )  \\boldsymbol{c}\\wedge \\boldsymbol{d} \\end{equation*}"
      ],
      "text/plain": [
       "(a.d)*b^c - (a.c)*b^d + (a.b)*c^d"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a | (b ^ c ^ d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*}  0  \\end{equation*}"
      ],
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(a | (b ^ c)) + (c | (a ^ b)) + (b | (c ^ a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} 3 \\boldsymbol{a}\\wedge \\boldsymbol{b}\\wedge \\boldsymbol{c} \\end{equation*}"
      ],
      "text/plain": [
       "3*a^b^c"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a * (b ^ c) - b * (a ^ c) + c * (a ^ b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} 4 \\boldsymbol{a}\\wedge \\boldsymbol{b}\\wedge \\boldsymbol{c}\\wedge \\boldsymbol{d} \\end{equation*}"
      ],
      "text/plain": [
       "4*a^b^c^d"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a * (b ^ c ^ d) - b * (a ^ c ^ d) + c * (a ^ b ^ d) - d * (a ^ b ^ c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} - \\left (\\boldsymbol{a}\\cdot \\boldsymbol{c}\\right )  \\left (\\boldsymbol{b}\\cdot \\boldsymbol{d}\\right )  + \\left (\\boldsymbol{a}\\cdot \\boldsymbol{d}\\right )  \\left (\\boldsymbol{b}\\cdot \\boldsymbol{c}\\right )  \\end{equation*}"
      ],
      "text/plain": [
       "-(a.c)*(b.d) + (a.d)*(b.c)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(a ^ b) | (c ^ d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} - \\left (\\boldsymbol{a}\\cdot \\boldsymbol{c}\\right )  \\left (\\boldsymbol{b}\\cdot \\boldsymbol{d}\\right )  + \\left (\\boldsymbol{a}\\cdot \\boldsymbol{d}\\right )  \\left (\\boldsymbol{b}\\cdot \\boldsymbol{c}\\right )  \\end{equation*}"
      ],
      "text/plain": [
       "-(a.c)*(b.d) + (a.d)*(b.c)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "((a ^ b) | c) | d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} - \\left (\\boldsymbol{b}\\cdot \\boldsymbol{d}\\right )  \\boldsymbol{a}\\wedge \\boldsymbol{c} + \\left (\\boldsymbol{b}\\cdot \\boldsymbol{c}\\right )  \\boldsymbol{a}\\wedge \\boldsymbol{d} + \\left (\\boldsymbol{a}\\cdot \\boldsymbol{d}\\right )  \\boldsymbol{b}\\wedge \\boldsymbol{c} - \\left (\\boldsymbol{a}\\cdot \\boldsymbol{c}\\right )  \\boldsymbol{b}\\wedge \\boldsymbol{d} \\end{equation*}"
      ],
      "text/plain": [
       "-(b.d)*a^c + (b.c)*a^d + (a.d)*b^c - (a.c)*b^d"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Ga.com(a ^ b, c ^ d)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Dirac.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "from __future__ import absolute_import, division\n",
    "from __future__ import print_function\n",
    "import sys\n",
    "from sympy import symbols, sin, cos\n",
    "from galgebra.printer import Format, xpdf, Print_Function\n",
    "from galgebra.ga import Ga"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\left( t, \\  x, \\  y, \\  z\\right)$"
      ],
      "text/plain": [
       "(t, x, y, z)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Format()\n",
    "coords = symbols('t x y z', real=True)\n",
    "coords"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "(st4d, g0, g1, g2, g3) = Ga.build(\n",
    "    'gamma*t|x|y|z', g=[1, -1, -1, -1], coords=coords)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*}  \\boldsymbol{\\gamma }_{t} \\end{equation*}"
      ],
      "text/plain": [
       "gamma_t"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*}  \\boldsymbol{\\gamma }_{x} \\end{equation*}"
      ],
      "text/plain": [
       "gamma_x"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*}  \\boldsymbol{\\gamma }_{y} \\end{equation*}"
      ],
      "text/plain": [
       "gamma_y"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*}  \\boldsymbol{\\gamma }_{z} \\end{equation*}"
      ],
      "text/plain": [
       "gamma_z"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*}  \\boldsymbol{\\gamma }_{t}\\wedge \\boldsymbol{\\gamma }_{x}\\wedge \\boldsymbol{\\gamma }_{y}\\wedge \\boldsymbol{\\gamma }_{z} \\end{equation*}"
      ],
      "text/plain": [
       "gamma_t^gamma_x^gamma_y^gamma_z"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "I = st4d.i\n",
    "I"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "(m, e) = symbols('m e')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle m$"
      ],
      "text/plain": [
       "m"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle e$"
      ],
      "text/plain": [
       "e"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "e"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} A = A^{t}  \\boldsymbol{\\gamma }_{t} + A^{x}  \\boldsymbol{\\gamma }_{x} + A^{y}  \\boldsymbol{\\gamma }_{y} + A^{z}  \\boldsymbol{\\gamma }_{z} \\end{equation*}"
      ],
      "text/plain": [
       "A__t*gamma_t + A__x*gamma_x + A__y*gamma_y + A__z*gamma_z"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 4-Vector Potential\n",
    "A = st4d.mv('A', 'vector', f=True)\n",
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} psi = \\psi    + \\psi ^{tx}  \\boldsymbol{\\gamma }_{t}\\wedge \\boldsymbol{\\gamma }_{x} + \\psi ^{ty}  \\boldsymbol{\\gamma }_{t}\\wedge \\boldsymbol{\\gamma }_{y} + \\psi ^{tz}  \\boldsymbol{\\gamma }_{t}\\wedge \\boldsymbol{\\gamma }_{z} + \\psi ^{xy}  \\boldsymbol{\\gamma }_{x}\\wedge \\boldsymbol{\\gamma }_{y} + \\psi ^{xz}  \\boldsymbol{\\gamma }_{x}\\wedge \\boldsymbol{\\gamma }_{z} + \\psi ^{yz}  \\boldsymbol{\\gamma }_{y}\\wedge \\boldsymbol{\\gamma }_{z} + \\psi ^{txyz}  \\boldsymbol{\\gamma }_{t}\\wedge \\boldsymbol{\\gamma }_{x}\\wedge \\boldsymbol{\\gamma }_{y}\\wedge \\boldsymbol{\\gamma }_{z} \\end{equation*}"
      ],
      "text/plain": [
       "psi + psi__tx*gamma_t^gamma_x + psi__ty*gamma_t^gamma_y + psi__tz*gamma_t^gamma_z + psi__xy*gamma_x^gamma_y + psi__xz*gamma_x^gamma_z + psi__yz*gamma_y^gamma_z + psi__txyz*gamma_t^gamma_x^gamma_y^gamma_z"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 8-componentrealspinor\n",
    "psi = st4d.mv('psi', 'spinor', f=True)\n",
    "psi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} - \\boldsymbol{\\gamma }_{t}\\wedge \\boldsymbol{\\gamma }_{z} \\end{equation*}"
      ],
      "text/plain": [
       "-gamma_t^gamma_z"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sig_z = g3 * g0\n",
    "sig_z"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Dirac Equation $\\newcommand{bm}[1]{\\boldsymbol #1}\n",
    "\\nabla \\bm{\\psi} I \\sigma_{z}-e\\bm{A}\\bm{\\psi}-m\\bm{\\psi}\\gamma_{t} = 0$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} \\left ( - e A^{t}  \\psi   - e A^{x}  \\psi ^{tx}  - e A^{y}  \\psi ^{ty}  - e A^{z}  \\psi ^{tz}  - m \\psi   - \\partial_{y} \\psi ^{tx}  - \\partial_{z} \\psi ^{txyz}  + \\partial_{x} \\psi ^{ty}  + \\partial_{t} \\psi ^{xy} \\right ) \\boldsymbol{\\gamma }_{t} + \\left ( - e A^{t}  \\psi ^{tx}  - e A^{x}  \\psi   - e A^{y}  \\psi ^{xy}  - e A^{z}  \\psi ^{xz}  + m \\psi ^{tx}  + \\partial_{y} \\psi   - \\partial_{t} \\psi ^{ty}  - \\partial_{x} \\psi ^{xy}  + \\partial_{z} \\psi ^{yz} \\right ) \\boldsymbol{\\gamma }_{x} + \\left ( - e A^{t}  \\psi ^{ty}  + e A^{x}  \\psi ^{xy}  - e A^{y}  \\psi   - e A^{z}  \\psi ^{yz}  + m \\psi ^{ty}  - \\partial_{x} \\psi   + \\partial_{t} \\psi ^{tx}  - \\partial_{y} \\psi ^{xy}  - \\partial_{z} \\psi ^{xz} \\right ) \\boldsymbol{\\gamma }_{y} + \\left ( - e A^{t}  \\psi ^{tz}  + e A^{x}  \\psi ^{xz}  + e A^{y}  \\psi ^{yz}  - e A^{z}  \\psi   + m \\psi ^{tz}  + \\partial_{t} \\psi ^{txyz}  - \\partial_{z} \\psi ^{xy}  + \\partial_{y} \\psi ^{xz}  - \\partial_{x} \\psi ^{yz} \\right ) \\boldsymbol{\\gamma }_{z} + \\left ( - e A^{t}  \\psi ^{xy}  + e A^{x}  \\psi ^{ty}  - e A^{y}  \\psi ^{tx}  - e A^{z}  \\psi ^{txyz}  - m \\psi ^{xy}  - \\partial_{t} \\psi   + \\partial_{x} \\psi ^{tx}  + \\partial_{y} \\psi ^{ty}  + \\partial_{z} \\psi ^{tz} \\right ) \\boldsymbol{\\gamma }_{t}\\wedge \\boldsymbol{\\gamma }_{x}\\wedge \\boldsymbol{\\gamma }_{y} + \\left ( - e A^{t}  \\psi ^{xz}  + e A^{x}  \\psi ^{tz}  + e A^{y}  \\psi ^{txyz}  - e A^{z}  \\psi ^{tx}  - m \\psi ^{xz}  + \\partial_{x} \\psi ^{txyz}  + \\partial_{z} \\psi ^{ty}  - \\partial_{y} \\psi ^{tz}  - \\partial_{t} \\psi ^{yz} \\right ) \\boldsymbol{\\gamma }_{t}\\wedge \\boldsymbol{\\gamma }_{x}\\wedge \\boldsymbol{\\gamma }_{z} + \\left ( - e A^{t}  \\psi ^{yz}  - e A^{x}  \\psi ^{txyz}  + e A^{y}  \\psi ^{tz}  - e A^{z}  \\psi ^{ty}  - m \\psi ^{yz}  - \\partial_{z} \\psi ^{tx}  + \\partial_{y} \\psi ^{txyz}  + \\partial_{x} \\psi ^{tz}  + \\partial_{t} \\psi ^{xz} \\right ) \\boldsymbol{\\gamma }_{t}\\wedge \\boldsymbol{\\gamma }_{y}\\wedge \\boldsymbol{\\gamma }_{z} + \\left ( - e A^{t}  \\psi ^{txyz}  - e A^{x}  \\psi ^{yz}  + e A^{y}  \\psi ^{xz}  - e A^{z}  \\psi ^{xy}  + m \\psi ^{txyz}  + \\partial_{z} \\psi   - \\partial_{t} \\psi ^{tz}  - \\partial_{x} \\psi ^{xz}  - \\partial_{y} \\psi ^{yz} \\right ) \\boldsymbol{\\gamma }_{x}\\wedge \\boldsymbol{\\gamma }_{y}\\wedge \\boldsymbol{\\gamma }_{z} \\end{equation*}"
      ],
      "text/plain": [
       "(-e*A__t*psi - e*A__x*psi__tx - e*A__y*psi__ty - e*A__z*psi__tz - m*psi - D{y}psi__tx - D{z}psi__txyz + D{x}psi__ty + D{t}psi__xy)*gamma_t + (-e*A__t*psi__tx - e*A__x*psi - e*A__y*psi__xy - e*A__z*psi__xz + m*psi__tx + D{y}psi - D{t}psi__ty - D{x}psi__xy + D{z}psi__yz)*gamma_x + (-e*A__t*psi__ty + e*A__x*psi__xy - e*A__y*psi - e*A__z*psi__yz + m*psi__ty - D{x}psi + D{t}psi__tx - D{y}psi__xy - D{z}psi__xz)*gamma_y + (-e*A__t*psi__tz + e*A__x*psi__xz + e*A__y*psi__yz - e*A__z*psi + m*psi__tz + D{t}psi__txyz - D{z}psi__xy + D{y}psi__xz - D{x}psi__yz)*gamma_z + (-e*A__t*psi__xy + e*A__x*psi__ty - e*A__y*psi__tx - e*A__z*psi__txyz - m*psi__xy - D{t}psi + D{x}psi__tx + D{y}psi__ty + D{z}psi__tz)*gamma_t^gamma_x^gamma_y + (-e*A__t*psi__xz + e*A__x*psi__tz + e*A__y*psi__txyz - e*A__z*psi__tx - m*psi__xz + D{x}psi__txyz + D{z}psi__ty - D{y}psi__tz - D{t}psi__yz)*gamma_t^gamma_x^gamma_z + (-e*A__t*psi__yz - e*A__x*psi__txyz + e*A__y*psi__tz - e*A__z*psi__ty - m*psi__yz - D{z}psi__tx + D{y}psi__txyz + D{x}psi__tz + D{t}psi__xz)*gamma_t^gamma_y^gamma_z + (-e*A__t*psi__txyz - e*A__x*psi__yz + e*A__y*psi__xz - e*A__z*psi__xy + m*psi__txyz + D{z}psi - D{t}psi__tz - D{x}psi__xz - D{y}psi__yz)*gamma_x^gamma_y^gamma_z"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dirac_eq = (st4d.grad * psi) * I * sig_z - e * A * psi - m * psi * g0\n",
    "dirac_eq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*}  \\begin{aligned}[t]  & \\left ( - e A^{t}  \\psi   - e A^{x}  \\psi ^{tx}  - e A^{y}  \\psi ^{ty}  - e A^{z}  \\psi ^{tz}  - m \\psi   - \\partial_{y} \\psi ^{tx}  - \\partial_{z} \\psi ^{txyz}  + \\partial_{x} \\psi ^{ty}  + \\partial_{t} \\psi ^{xy} \\right ) \\boldsymbol{\\gamma }_{t} + \\left ( - e A^{t}  \\psi ^{tx}  - e A^{x}  \\psi   - e A^{y}  \\psi ^{xy}  - e A^{z}  \\psi ^{xz}  + m \\psi ^{tx}  + \\partial_{y} \\psi   - \\partial_{t} \\psi ^{ty}  - \\partial_{x} \\psi ^{xy}  + \\partial_{z} \\psi ^{yz} \\right ) \\boldsymbol{\\gamma }_{x} + \\left ( - e A^{t}  \\psi ^{ty}  + e A^{x}  \\psi ^{xy}  - e A^{y}  \\psi   - e A^{z}  \\psi ^{yz}  + m \\psi ^{ty}  - \\partial_{x} \\psi   + \\partial_{t} \\psi ^{tx}  - \\partial_{y} \\psi ^{xy}  - \\partial_{z} \\psi ^{xz} \\right ) \\boldsymbol{\\gamma }_{y} + \\left ( - e A^{t}  \\psi ^{tz}  + e A^{x}  \\psi ^{xz}  + e A^{y}  \\psi ^{yz}  - e A^{z}  \\psi   + m \\psi ^{tz}  + \\partial_{t} \\psi ^{txyz}  - \\partial_{z} \\psi ^{xy}  + \\partial_{y} \\psi ^{xz}  - \\partial_{x} \\psi ^{yz} \\right ) \\boldsymbol{\\gamma }_{z} \\\\  &  + \\left ( - e A^{t}  \\psi ^{xy}  + e A^{x}  \\psi ^{ty}  - e A^{y}  \\psi ^{tx}  - e A^{z}  \\psi ^{txyz}  - m \\psi ^{xy}  - \\partial_{t} \\psi   + \\partial_{x} \\psi ^{tx}  + \\partial_{y} \\psi ^{ty}  + \\partial_{z} \\psi ^{tz} \\right ) \\boldsymbol{\\gamma }_{t}\\wedge \\boldsymbol{\\gamma }_{x}\\wedge \\boldsymbol{\\gamma }_{y} + \\left ( - e A^{t}  \\psi ^{xz}  + e A^{x}  \\psi ^{tz}  + e A^{y}  \\psi ^{txyz}  - e A^{z}  \\psi ^{tx}  - m \\psi ^{xz}  + \\partial_{x} \\psi ^{txyz}  + \\partial_{z} \\psi ^{ty}  - \\partial_{y} \\psi ^{tz}  - \\partial_{t} \\psi ^{yz} \\right ) \\boldsymbol{\\gamma }_{t}\\wedge \\boldsymbol{\\gamma }_{x}\\wedge \\boldsymbol{\\gamma }_{z} + \\left ( - e A^{t}  \\psi ^{yz}  - e A^{x}  \\psi ^{txyz}  + e A^{y}  \\psi ^{tz}  - e A^{z}  \\psi ^{ty}  - m \\psi ^{yz}  - \\partial_{z} \\psi ^{tx}  + \\partial_{y} \\psi ^{txyz}  + \\partial_{x} \\psi ^{tz}  + \\partial_{t} \\psi ^{xz} \\right ) \\boldsymbol{\\gamma }_{t}\\wedge \\boldsymbol{\\gamma }_{y}\\wedge \\boldsymbol{\\gamma }_{z} + \\left ( - e A^{t}  \\psi ^{txyz}  - e A^{x}  \\psi ^{yz}  + e A^{y}  \\psi ^{xz}  - e A^{z}  \\psi ^{xy}  + m \\psi ^{txyz}  + \\partial_{z} \\psi   - \\partial_{t} \\psi ^{tz}  - \\partial_{x} \\psi ^{xz}  - \\partial_{y} \\psi ^{yz} \\right ) \\boldsymbol{\\gamma }_{x}\\wedge \\boldsymbol{\\gamma }_{y}\\wedge \\boldsymbol{\\gamma }_{z}  \\end{aligned}  \\end{equation*}"
      ],
      "text/plain": [
       " (-e*A__t*psi - e*A__x*psi__tx - e*A__y*psi__ty - e*A__z*psi__tz - m*psi - D{y}psi__tx - D{z}psi__txyz + D{x}psi__ty + D{t}psi__xy)*gamma_t + (-e*A__t*psi__tx - e*A__x*psi - e*A__y*psi__xy - e*A__z*psi__xz + m*psi__tx + D{y}psi - D{t}psi__ty - D{x}psi__xy + D{z}psi__yz)*gamma_x + (-e*A__t*psi__ty + e*A__x*psi__xy - e*A__y*psi - e*A__z*psi__yz + m*psi__ty - D{x}psi + D{t}psi__tx - D{y}psi__xy - D{z}psi__xz)*gamma_y + (-e*A__t*psi__tz + e*A__x*psi__xz + e*A__y*psi__yz - e*A__z*psi + m*psi__tz + D{t}psi__txyz - D{z}psi__xy + D{y}psi__xz - D{x}psi__yz)*gamma_z\n",
       " + (-e*A__t*psi__xy + e*A__x*psi__ty - e*A__y*psi__tx - e*A__z*psi__txyz - m*psi__xy - D{t}psi + D{x}psi__tx + D{y}psi__ty + D{z}psi__tz)*gamma_t^gamma_x^gamma_y + (-e*A__t*psi__xz + e*A__x*psi__tz + e*A__y*psi__txyz - e*A__z*psi__tx - m*psi__xz + D{x}psi__txyz + D{z}psi__ty - D{y}psi__tz - D{t}psi__yz)*gamma_t^gamma_x^gamma_z + (-e*A__t*psi__yz - e*A__x*psi__txyz + e*A__y*psi__tz - e*A__z*psi__ty - m*psi__yz - D{z}psi__tx + D{y}psi__txyz + D{x}psi__tz + D{t}psi__xz)*gamma_t^gamma_y^gamma_z + (-e*A__t*psi__txyz - e*A__x*psi__yz + e*A__y*psi__xz - e*A__z*psi__xy + m*psi__txyz + D{z}psi - D{t}psi__tz - D{x}psi__xz - D{y}psi__yz)*gamma_x^gamma_y^gamma_z"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dirac_eq.Fmt(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*} \\left ( - e A^{t}  \\psi   - e A^{x}  \\psi ^{tx}  - e A^{y}  \\psi ^{ty}  - e A^{z}  \\psi ^{tz}  - m \\psi   - \\partial_{y} \\psi ^{tx}  - \\partial_{z} \\psi ^{txyz}  + \\partial_{x} \\psi ^{ty}  + \\partial_{t} \\psi ^{xy} \\right ) \\boldsymbol{\\gamma }_{t} + \\left ( - e A^{t}  \\psi ^{tx}  - e A^{x}  \\psi   - e A^{y}  \\psi ^{xy}  - e A^{z}  \\psi ^{xz}  + m \\psi ^{tx}  + \\partial_{y} \\psi   - \\partial_{t} \\psi ^{ty}  - \\partial_{x} \\psi ^{xy}  + \\partial_{z} \\psi ^{yz} \\right ) \\boldsymbol{\\gamma }_{x} + \\left ( - e A^{t}  \\psi ^{ty}  + e A^{x}  \\psi ^{xy}  - e A^{y}  \\psi   - e A^{z}  \\psi ^{yz}  + m \\psi ^{ty}  - \\partial_{x} \\psi   + \\partial_{t} \\psi ^{tx}  - \\partial_{y} \\psi ^{xy}  - \\partial_{z} \\psi ^{xz} \\right ) \\boldsymbol{\\gamma }_{y} + \\left ( - e A^{t}  \\psi ^{tz}  + e A^{x}  \\psi ^{xz}  + e A^{y}  \\psi ^{yz}  - e A^{z}  \\psi   + m \\psi ^{tz}  + \\partial_{t} \\psi ^{txyz}  - \\partial_{z} \\psi ^{xy}  + \\partial_{y} \\psi ^{xz}  - \\partial_{x} \\psi ^{yz} \\right ) \\boldsymbol{\\gamma }_{z} + \\left ( - e A^{t}  \\psi ^{xy}  + e A^{x}  \\psi ^{ty}  - e A^{y}  \\psi ^{tx}  - e A^{z}  \\psi ^{txyz}  - m \\psi ^{xy}  - \\partial_{t} \\psi   + \\partial_{x} \\psi ^{tx}  + \\partial_{y} \\psi ^{ty}  + \\partial_{z} \\psi ^{tz} \\right ) \\boldsymbol{\\gamma }_{t}\\wedge \\boldsymbol{\\gamma }_{x}\\wedge \\boldsymbol{\\gamma }_{y} + \\left ( - e A^{t}  \\psi ^{xz}  + e A^{x}  \\psi ^{tz}  + e A^{y}  \\psi ^{txyz}  - e A^{z}  \\psi ^{tx}  - m \\psi ^{xz}  + \\partial_{x} \\psi ^{txyz}  + \\partial_{z} \\psi ^{ty}  - \\partial_{y} \\psi ^{tz}  - \\partial_{t} \\psi ^{yz} \\right ) \\boldsymbol{\\gamma }_{t}\\wedge \\boldsymbol{\\gamma }_{x}\\wedge \\boldsymbol{\\gamma }_{z} + \\left ( - e A^{t}  \\psi ^{yz}  - e A^{x}  \\psi ^{txyz}  + e A^{y}  \\psi ^{tz}  - e A^{z}  \\psi ^{ty}  - m \\psi ^{yz}  - \\partial_{z} \\psi ^{tx}  + \\partial_{y} \\psi ^{txyz}  + \\partial_{x} \\psi ^{tz}  + \\partial_{t} \\psi ^{xz} \\right ) \\boldsymbol{\\gamma }_{t}\\wedge \\boldsymbol{\\gamma }_{y}\\wedge \\boldsymbol{\\gamma }_{z} + \\left ( - e A^{t}  \\psi ^{txyz}  - e A^{x}  \\psi ^{yz}  + e A^{y}  \\psi ^{xz}  - e A^{z}  \\psi ^{xy}  + m \\psi ^{txyz}  + \\partial_{z} \\psi   - \\partial_{t} \\psi ^{tz}  - \\partial_{x} \\psi ^{xz}  - \\partial_{y} \\psi ^{yz} \\right ) \\boldsymbol{\\gamma }_{x}\\wedge \\boldsymbol{\\gamma }_{y}\\wedge \\boldsymbol{\\gamma }_{z} \\end{equation*}"
      ],
      "text/plain": [
       "(-e*A__t*psi - e*A__x*psi__tx - e*A__y*psi__ty - e*A__z*psi__tz - m*psi - D{y}psi__tx - D{z}psi__txyz + D{x}psi__ty + D{t}psi__xy)*gamma_t + (-e*A__t*psi__tx - e*A__x*psi - e*A__y*psi__xy - e*A__z*psi__xz + m*psi__tx + D{y}psi - D{t}psi__ty - D{x}psi__xy + D{z}psi__yz)*gamma_x + (-e*A__t*psi__ty + e*A__x*psi__xy - e*A__y*psi - e*A__z*psi__yz + m*psi__ty - D{x}psi + D{t}psi__tx - D{y}psi__xy - D{z}psi__xz)*gamma_y + (-e*A__t*psi__tz + e*A__x*psi__xz + e*A__y*psi__yz - e*A__z*psi + m*psi__tz + D{t}psi__txyz - D{z}psi__xy + D{y}psi__xz - D{x}psi__yz)*gamma_z + (-e*A__t*psi__xy + e*A__x*psi__ty - e*A__y*psi__tx - e*A__z*psi__txyz - m*psi__xy - D{t}psi + D{x}psi__tx + D{y}psi__ty + D{z}psi__tz)*gamma_t^gamma_x^gamma_y + (-e*A__t*psi__xz + e*A__x*psi__tz + e*A__y*psi__txyz - e*A__z*psi__tx - m*psi__xz + D{x}psi__txyz + D{z}psi__ty - D{y}psi__tz - D{t}psi__yz)*gamma_t^gamma_x^gamma_z + (-e*A__t*psi__yz - e*A__x*psi__txyz + e*A__y*psi__tz - e*A__z*psi__ty - m*psi__yz - D{z}psi__tx + D{y}psi__txyz + D{x}psi__tz + D{t}psi__xz)*gamma_t^gamma_y^gamma_z + (-e*A__t*psi__txyz - e*A__x*psi__yz + e*A__y*psi__xz - e*A__z*psi__xy + m*psi__txyz + D{z}psi - D{t}psi__tz - D{x}psi__xz - D{y}psi__yz)*gamma_x^gamma_y^gamma_z"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dirac_eq = dirac_eq.simplify()\n",
    "dirac_eq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "\\begin{equation*}  \\begin{aligned}[t]  & \\left ( - e A^{t}  \\psi   - e A^{x}  \\psi ^{tx}  - e A^{y}  \\psi ^{ty}  - e A^{z}  \\psi ^{tz}  - m \\psi   - \\partial_{y} \\psi ^{tx}  - \\partial_{z} \\psi ^{txyz}  + \\partial_{x} \\psi ^{ty}  + \\partial_{t} \\psi ^{xy} \\right ) \\boldsymbol{\\gamma }_{t} + \\left ( - e A^{t}  \\psi ^{tx}  - e A^{x}  \\psi   - e A^{y}  \\psi ^{xy}  - e A^{z}  \\psi ^{xz}  + m \\psi ^{tx}  + \\partial_{y} \\psi   - \\partial_{t} \\psi ^{ty}  - \\partial_{x} \\psi ^{xy}  + \\partial_{z} \\psi ^{yz} \\right ) \\boldsymbol{\\gamma }_{x} + \\left ( - e A^{t}  \\psi ^{ty}  + e A^{x}  \\psi ^{xy}  - e A^{y}  \\psi   - e A^{z}  \\psi ^{yz}  + m \\psi ^{ty}  - \\partial_{x} \\psi   + \\partial_{t} \\psi ^{tx}  - \\partial_{y} \\psi ^{xy}  - \\partial_{z} \\psi ^{xz} \\right ) \\boldsymbol{\\gamma }_{y} + \\left ( - e A^{t}  \\psi ^{tz}  + e A^{x}  \\psi ^{xz}  + e A^{y}  \\psi ^{yz}  - e A^{z}  \\psi   + m \\psi ^{tz}  + \\partial_{t} \\psi ^{txyz}  - \\partial_{z} \\psi ^{xy}  + \\partial_{y} \\psi ^{xz}  - \\partial_{x} \\psi ^{yz} \\right ) \\boldsymbol{\\gamma }_{z} \\\\  &  + \\left ( - e A^{t}  \\psi ^{xy}  + e A^{x}  \\psi ^{ty}  - e A^{y}  \\psi ^{tx}  - e A^{z}  \\psi ^{txyz}  - m \\psi ^{xy}  - \\partial_{t} \\psi   + \\partial_{x} \\psi ^{tx}  + \\partial_{y} \\psi ^{ty}  + \\partial_{z} \\psi ^{tz} \\right ) \\boldsymbol{\\gamma }_{t}\\wedge \\boldsymbol{\\gamma }_{x}\\wedge \\boldsymbol{\\gamma }_{y} + \\left ( - e A^{t}  \\psi ^{xz}  + e A^{x}  \\psi ^{tz}  + e A^{y}  \\psi ^{txyz}  - e A^{z}  \\psi ^{tx}  - m \\psi ^{xz}  + \\partial_{x} \\psi ^{txyz}  + \\partial_{z} \\psi ^{ty}  - \\partial_{y} \\psi ^{tz}  - \\partial_{t} \\psi ^{yz} \\right ) \\boldsymbol{\\gamma }_{t}\\wedge \\boldsymbol{\\gamma }_{x}\\wedge \\boldsymbol{\\gamma }_{z} + \\left ( - e A^{t}  \\psi ^{yz}  - e A^{x}  \\psi ^{txyz}  + e A^{y}  \\psi ^{tz}  - e A^{z}  \\psi ^{ty}  - m \\psi ^{yz}  - \\partial_{z} \\psi ^{tx}  + \\partial_{y} \\psi ^{txyz}  + \\partial_{x} \\psi ^{tz}  + \\partial_{t} \\psi ^{xz} \\right ) \\boldsymbol{\\gamma }_{t}\\wedge \\boldsymbol{\\gamma }_{y}\\wedge \\boldsymbol{\\gamma }_{z} + \\left ( - e A^{t}  \\psi ^{txyz}  - e A^{x}  \\psi ^{yz}  + e A^{y}  \\psi ^{xz}  - e A^{z}  \\psi ^{xy}  + m \\psi ^{txyz}  + \\partial_{z} \\psi   - \\partial_{t} \\psi ^{tz}  - \\partial_{x} \\psi ^{xz}  - \\partial_{y} \\psi ^{yz} \\right ) \\boldsymbol{\\gamma }_{x}\\wedge \\boldsymbol{\\gamma }_{y}\\wedge \\boldsymbol{\\gamma }_{z}  \\end{aligned}  \\end{equation*}"
      ],
      "text/plain": [
       " (-e*A__t*psi - e*A__x*psi__tx - e*A__y*psi__ty - e*A__z*psi__tz - m*psi - D{y}psi__tx - D{z}psi__txyz + D{x}psi__ty + D{t}psi__xy)*gamma_t + (-e*A__t*psi__tx - e*A__x*psi - e*A__y*psi__xy - e*A__z*psi__xz + m*psi__tx + D{y}psi - D{t}psi__ty - D{x}psi__xy + D{z}psi__yz)*gamma_x + (-e*A__t*psi__ty + e*A__x*psi__xy - e*A__y*psi - e*A__z*psi__yz + m*psi__ty - D{x}psi + D{t}psi__tx - D{y}psi__xy - D{z}psi__xz)*gamma_y + (-e*A__t*psi__tz + e*A__x*psi__xz + e*A__y*psi__yz - e*A__z*psi + m*psi__tz + D{t}psi__txyz - D{z}psi__xy + D{y}psi__xz - D{x}psi__yz)*gamma_z\n",
       " + (-e*A__t*psi__xy + e*A__x*psi__ty - e*A__y*psi__tx - e*A__z*psi__txyz - m*psi__xy - D{t}psi + D{x}psi__tx + D{y}psi__ty + D{z}psi__tz)*gamma_t^gamma_x^gamma_y + (-e*A__t*psi__xz + e*A__x*psi__tz + e*A__y*psi__txyz - e*A__z*psi__tx - m*psi__xz + D{x}psi__txyz + D{z}psi__ty - D{y}psi__tz - D{t}psi__yz)*gamma_t^gamma_x^gamma_z + (-e*A__t*psi__yz - e*A__x*psi__txyz + e*A__y*psi__tz - e*A__z*psi__ty - m*psi__yz - D{z}psi__tx + D{y}psi__txyz + D{x}psi__tz + D{t}psi__xz)*gamma_t^gamma_y^gamma_z + (-e*A__t*psi__txyz - e*A__x*psi__yz + e*A__y*psi__xz - e*A__z*psi__xy + m*psi__txyz + D{z}psi - D{t}psi__tz - D{x}psi__xz - D{y}psi__yz)*gamma_x^gamma_y^gamma_z"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dirac_eq.Fmt(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
